/**
 * ...
 * @author Rob Dravenstott
 * 
 * Configuration dialogue box to allow user updates to parameters
 * 
 */

import com.chumby.util.Delegate; 
class WeatherRadarConfig 
{
	private static var _app_root:MovieClip;
	private var savenewsettingsFunc:Function;
	private static var _text_holder:MovieClip = null;
	private static var _x_scale_factor:Number = 1;
	private static var _y_scale_factor:Number = 1;	
	private var cp:MovieClip = null;
	private var radarLocationArray:Array = null;
	private var radarLocationPosition:Number = 0;
	private var radarTypeArray:Array = new Array();
	private var radarTypePosition:Number = 0;
	
	public var radar_zoom:Number = 150;  // 100 = Actual size
	public var radar_id:String = "FTG";  // ftg=Denver area
	public var radar_type:String = "N0R";  //NCR=Composite, N0R=Base, N0S=Storm, N0V=Velocity, N1P=One hour preciptiation, NTP=Total shorm precipitation
	public var radar_max_images:Number = 5; // Max number of images for the sequence
	

	public function WeatherRadarConfig (app_root:MovieClip, settings:Object, saveNewSettings:Function)
	{
		_app_root = app_root;
		this.savenewsettingsFunc = saveNewSettings;
		
		if (settings.radar_zoom != undefined)
			this.radar_zoom = Number(settings.radar_zoom);
		if (settings.radar_type != undefined)
			this.radar_type = settings.radar_type;
		if (settings.max_images != undefined)
			this.radar_max_images = Number(settings.radar_max_images);
		if (settings.radar_id != undefined)
			this.radar_id = String(settings.radar_id).toUpperCase();
		
		radarLocationArray = createRadarLocationArray();
		
		radarTypeArray[0] = { type:"NCR", descr:"Composite" };
		radarTypeArray[1] = { type:"N0R", descr:"Base" };
		radarTypeArray[2] = { type:"N0V", descr:"Velocity" };
		radarTypeArray[3] = { type:"N0Z", descr:"Long Rng" };
		radarTypeArray[4] = { type:"N1P", descr:"1hr Precip" };
		radarTypeArray[5] = { type:"NTP", descr:"Tot Precip" };
//		radarTypeArray[6] = { type:"N0S", descr:"Storm" };  -- Seems to have been discontinued by NWS
						
		// Move to the saved/default state/city
		while ((this.radar_id != radarLocationArray[radarLocationPosition].id.toUpperCase())
		       && (radarLocationPosition < radarLocationArray.length))
		{
			radarLocationPosition++;
		}
		//Catch the case where radar_id not found
		if (radarLocationPosition >= radarLocationArray.length)
			radarLocationPosition = 0;
		
		// Move to the current type
		while ((this.radar_type != radarTypeArray[radarTypePosition].type)
		       && (radarTypePosition < radarTypeArray.length))
		{
			radarTypePosition++;
		}
		if (radarTypePosition >= radarTypeArray.length)
			radarTypePosition = 0;
		
		renderGUI();
	}
	
	private function renderGUI()
	{
		cp = _app_root.createEmptyMovieClip("cp", _app_root.getNextHighestDepth());
		
		// Set background color
		GraphicUtils.createRect(cp, "background", 0, 0, 320, 240, 0x000000, 100);

		var tf:TextFormat = new TextFormat();
		tf.align = "center";
		tf.color = 0xFFFFFF; //white text
		tf.bold = true;
		tf.underline = false;
		tf.font = "_sans"; //also _serif and _typewriter available for chumby

		GraphicUtils.createRect(cp, "top_banner", 0, 0, 320, 35, 0xFF33FF, 20);
		
		cp.createTextField("radar_st", this.cp.getNextHighestDepth(), 10, 5, 310, 35);
		tf.size = 20;
		cp.radar_st.setNewTextFormat(tf);
		cp.radar_st.text = "Radar Setup";

		cp.createTextField("radar_cancel_txt", this.cp.getNextHighestDepth(), 283, 5, 35, 35);
		tf.size = 20;
		cp.radar_cancel_txt.setNewTextFormat(tf);
		cp.radar_cancel_txt.text = "X";

		GraphicUtils.createRect(cp, "radar_cancel", 283, 2, 35, 30, 0x000000, 0, 2);

		GraphicUtils.createTextArrows(cp, tf, "radar_st_bottom", "radar_st_txt", "arrow_up_st", "arrow_down_st", 5, 40, 45)
		cp["radar_st_bottom"].text = "State:";
		cp["radar_st_txt"].text = radarLocationArray[radarLocationPosition].st;
		
		GraphicUtils.createTextArrows(cp, tf, "radar_city_bottom", "radar_city_txt", "arrow_up_city", "arrow_down_city", 120, 40, 140)
		cp["radar_city_bottom"].text = "City or Region:";
		cp["radar_city_txt"].text = radarLocationArray[radarLocationPosition].city;
	
		GraphicUtils.createTextArrows(cp, tf, "radar_zoom", "radar_zoom_txt", "arrow_up_zoom", "arrow_down_zoom", 5, 132, 60)
		cp["radar_zoom"].text = "Zoom:";
		cp["radar_zoom_txt"].text = String(radar_zoom)+"%";
	
		cp.createTextField("radar_type_txt_below", this.cp.getNextHighestDepth(), 130, 190, 80, 60);
		tf.size = 14;
		tf.underline = false;
		cp.radar_type_txt_below.setNewTextFormat(tf);
		cp.radar_type_txt_below.text = radarTypeArray[radarTypePosition].descr;

		GraphicUtils.createTextArrows(cp, tf, "radar_type", "radar_type_txt", "arrow_up_type", "arrow_down_type", 130, 132, 60)
		cp["radar_type"].text = "View:";
		cp["radar_type_txt"].text = radarTypeArray[radarTypePosition].type;

		GraphicUtils.createRect(cp, "disclaimer", 0, 220, 320, 20, 0xFF33FF, 20);
		
		cp.createTextField("radar_disclaimer", this.cp.getNextHighestDepth(), 0, 220, 320, 20);
		tf.size = 8;
		tf.align = "center";
		tf.underline = false;
		cp.radar_disclaimer.setNewTextFormat(tf);
		cp.radar_disclaimer.text = "Public domain radar images from the National Weather Service. v1.2";
		
		this.cp.createTextField("close_btn_title", this.cp.getNextHighestDepth(), 252, 150, 66, 60);
		tf.size = 18;
		tf.align = "center";
		this.cp.close_btn_title.setNewTextFormat(tf);
		this.cp.close_btn_title.text = "Save &\nClose";

		GraphicUtils.createRect(cp, "close_btn", 251, 145, 66, 60, 0xFF33FF, 20, 2);

		this.cp.radar_cancel.onRelease = Delegate.create(this, this.cancelCP);
		this.cp.arrow_up_st.onPress = Delegate.create(this, this.arrowUpStPress);
		this.cp.arrow_up_st.onRelease = Delegate.create(this, this.arrowUpStRelease);
		this.cp.arrow_down_st.onPress = Delegate.create(this, this.arrowDownStPress);
		this.cp.arrow_down_st.onRelease = Delegate.create(this, this.arrowDownStRelease);
		this.cp.arrow_up_city.onPress = Delegate.create(this, this.arrowUpCityPress);
		this.cp.arrow_up_city.onRelease = Delegate.create(this, this.arrowUpCityRelease);
		this.cp.arrow_down_city.onPress = Delegate.create(this, this.arrowDownCityPress);
		this.cp.arrow_down_city.onRelease = Delegate.create(this, this.arrowDownCityRelease);
		this.cp.arrow_up_zoom.onPress = Delegate.create(this, this.arrowUpZoomPress);		
		this.cp.arrow_up_zoom.onRelease = Delegate.create(this, this.arrowUpZoomRelease);
		this.cp.arrow_down_zoom.onPress = Delegate.create(this, this.arrowDownZoomPress);
		this.cp.arrow_down_zoom.onRelease = Delegate.create(this, this.arrowDownZoomRelease);
		this.cp.arrow_up_type.onPress = Delegate.create(this, this.arrowUpTypePress);		
		this.cp.arrow_up_type.onRelease = Delegate.create(this, this.arrowUpTypeRelease);
		this.cp.arrow_down_type.onPress = Delegate.create(this, this.arrowDownTypePress);
		this.cp.arrow_down_type.onRelease = Delegate.create(this, this.arrowDownTypeRelease);
		this.cp.close_btn.onPress = Delegate.create(this, this.savePress);
		this.cp.close_btn.onRelease = Delegate.create(this, this.saveCP);
	}
	
	public function closeSettings ():Void 
	{
		delete this.cp.arrow_up_st.onRelease;
		delete this.cp.arrow_up_st.onPress;
		delete this.cp.arrow_down_st.onRelease;
		delete this.cp.arrow_down_st.Press;
		delete this.cp.arrow_up_city.onRelease;
		delete this.cp.arrow_up_city.onPress;
		delete this.cp.arrow_down_city.onRelease;
		delete this.cp.arrow_down_city.onPress;
		delete this.cp.arrow_up_zoom.onRelease;
		delete this.cp.arrow_up_zoom.onPress;
		delete this.cp.arrow_down_zoom.onRelease;
		delete this.cp.arrow_down_zoom.onPress;
		delete this.cp.arrow_up_type.onRelease;
		delete this.cp.arrow_up_type.onPress;
		delete this.cp.arrow_down_type.onRelease;
		delete this.cp.arrow_down_type.onPress;
		delete this.cp.close_btn.onPress;
		delete this.cp.close_btn.onRelease;
		delete this.cp.cancel_btn.onPress;
		this.cp.cancel_btn.removeMovieClip();
		this.cp.close_btn.removeMovieClip();
		this.cp.arrow_down_st.removeMovieClip();
		this.cp.arrow_down_st_drawing.removeMovieClip();		
		this.cp.arrow_up_st.removeMovieClip();
		this.cp.arrow_up_st_drawing.removeMovieClip();
		this.cp.arrow_down_city.removeMovieClip();
		this.cp.arrow_down_city_drawing.removeMovieClip();		
		this.cp.arrow_up_city.removeMovieClip();
		this.cp.arrow_up_city_drawing.removeMovieClip();
		this.cp.arrow_down_zoom.removeMovieClip();
		this.cp.arrow_down_zoom_drawing.removeMovieClip();		
		this.cp.arrow_up_zoom.removeMovieClip();
		this.cp.arrow_up_zoom_drawing.removeMovieClip();
		this.cp.arrow_down_type.removeMovieClip();
		this.cp.arrow_down_type_drawing.removeMovieClip();		
		this.cp.arrow_up_type.removeMovieClip();
		this.cp.arrow_up_type_drawing.removeMovieClip();
		this.cp.removeMovieClip();
	}

	private function cancelCP ():Void
	{
		this.radar_id = String(radarLocationArray[radarLocationPosition].id).toUpperCase();
		
		var settings:Object = { radar_zoom:String(this.radar_zoom), radar_type:this.radar_type, radar_max_images:String(this.radar_max_images), radar_id:String(this.radar_id).toUpperCase() };
		
		this.savenewsettingsFunc(settings, false);
	}
	
	private function savePress ():Void 
	{
		var myColor = new Color(this.cp.close_btn);
		myColor.setRGB(0x777777);
		showTextMessage("Saving...", 14);
	}
	
	private function saveCP ():Void 
	{
		var myColor = new Color(this.cp.close_btn);
		myColor.setRGB(0xFF33FF);

		this.radar_id = String(radarLocationArray[radarLocationPosition].id).toUpperCase();
		
		var settings:Object = { radar_zoom:String(this.radar_zoom), radar_type:this.radar_type, radar_max_images:String(this.radar_max_images), radar_id:String(this.radar_id).toUpperCase() };
		
		this.savenewsettingsFunc(settings, true);
	}

	public function arrowUpTypePress ():Void
	{
		var myColor = new Color(this.cp.arrow_up_type_drawing);
		myColor.setRGB(0x777777);
	}
	
	public function arrowUpTypeRelease ():Void
	{
		radarTypePosition--;
		if (radarTypePosition < 0)
			radarTypePosition = radarTypeArray.length - 1;
		
		radar_type = radarTypeArray[radarTypePosition].type;
		cp.radar_type_txt.text = radar_type;
		cp.radar_type_txt_below.text = radarTypeArray[radarTypePosition].descr;
		
		var myColor = new Color(this.cp.arrow_up_type_drawing);
		myColor.setRGB(0xFFFFFF);
	}

	public function arrowDownTypePress ():Void
	{
		var myColor = new Color(this.cp.arrow_down_type_drawing);
		myColor.setRGB(0x777777);
	}

	public function arrowDownTypeRelease ():Void
	{
		radarTypePosition++;
		if (radarTypePosition >= radarTypeArray.length)
			radarTypePosition = 0;
		
		radar_type = radarTypeArray[radarTypePosition].type;
		cp.radar_type_txt.text = radar_type;
		cp.radar_type_txt_below.text = radarTypeArray[radarTypePosition].descr;
		
		var myColor = new Color(this.cp.arrow_down_type_drawing);
		myColor.setRGB(0xFFFFFF);
	}

	
	public function arrowUpZoomPress ():Void
	{
		var myColor = new Color(this.cp.arrow_up_zoom_drawing);
		myColor.setRGB(0x777777);
	}
	
	public function arrowUpZoomRelease ():Void
	{
		radar_zoom = radar_zoom + 25;
		
		// set max zoom at 400
		if (radar_zoom > 400)
			radar_zoom = 400;
			
		cp.radar_zoom_txt.text = String(radar_zoom) + "%";

		var myColor = new Color(this.cp.arrow_up_zoom_drawing);
		myColor.setRGB(0xFFFFFF);
	}

	public function arrowDownZoomPress ():Void
	{
		var myColor = new Color(this.cp.arrow_down_zoom_drawing);
		myColor.setRGB(0x777777);
	}

	public function arrowDownZoomRelease ():Void
	{
		radar_zoom = radar_zoom - 25;
		
		// set min zoom @100
		if (radar_zoom < 25)
			radar_zoom = 25;
			
		cp.radar_zoom_txt.text = String(radar_zoom)+"%";

		var myColor = new Color(this.cp.arrow_down_zoom_drawing);
		myColor.setRGB(0xFFFFFF);
	}

	public function arrowUpStPress ():Void
	{
		var myColor = new Color(this.cp.arrow_up_st_drawing);
		myColor.setRGB(0x777777);
	}
	
	public function arrowUpStRelease ():Void
	{
		var currSt:String = radarLocationArray[radarLocationPosition].st;
		
		while (   (currSt == radarLocationArray[radarLocationPosition].st)
		       && (radarLocationPosition >= 0))
		{
			radarLocationPosition--;
		}
		
		if (radarLocationPosition < 0)
			radarLocationPosition = radarLocationArray.length - 1;
			
		cp.radar_st_txt.text = radarLocationArray[radarLocationPosition].st;
		cp.radar_city_txt.text = radarLocationArray[radarLocationPosition].city;
		this.radar_id = String(radarLocationArray[radarLocationPosition].id).toUpperCase();

		var myColor = new Color(this.cp.arrow_up_st_drawing);
		myColor.setRGB(0xFFFFFF);
	}

	public function arrowDownStPress ():Void
	{
		var myColor = new Color(this.cp.arrow_down_st_drawing);
		myColor.setRGB(0x777777);
	}
	
	public function arrowDownStRelease ():Void
	{
		var currSt:String = radarLocationArray[radarLocationPosition].st;
		
		while (   (currSt == radarLocationArray[radarLocationPosition].st)
		       && (radarLocationPosition < radarLocationArray.length))
		{
			radarLocationPosition++;
		}

		if (radarLocationPosition >= radarLocationArray.length)
			radarLocationPosition = 0;
			
		cp.radar_st_txt.text = radarLocationArray[radarLocationPosition].st;
		cp.radar_city_txt.text = radarLocationArray[radarLocationPosition].city;
		this.radar_id = String(radarLocationArray[radarLocationPosition].id).toUpperCase();

		var myColor = new Color(this.cp.arrow_down_st_drawing);
		myColor.setRGB(0xFFFFFF);
	}
	
	public function arrowUpCityPress ():Void
	{
		var myColor = new Color(this.cp.arrow_up_city_drawing);
		myColor.setRGB(0x777777);
	}
	
	public function arrowUpCityRelease ():Void
	{
		var currSt:String = radarLocationArray[radarLocationPosition].st;
		
		radarLocationPosition--;
		// Go back until we find our current state again
		while (   (currSt != radarLocationArray[radarLocationPosition].st)
		       && (radarLocationPosition >= 0))
		{
			radarLocationPosition--;
		}
		
		// If we've passed 0, we need to go back to find an instance of the state again
		if (radarLocationPosition < 0)
		{
			radarLocationPosition = radarLocationArray.length - 1;
			while (   (currSt != radarLocationArray[radarLocationPosition].st)
				   && (radarLocationPosition >= 0))
			{
				radarLocationPosition--;
			}
		}
					
		cp.radar_city_txt.text = radarLocationArray[radarLocationPosition].city;
		this.radar_id = String(radarLocationArray[radarLocationPosition].id).toUpperCase();

		var myColor = new Color(this.cp.arrow_up_city_drawing);
		myColor.setRGB(0xFFFFFF);
	}

	public function arrowDownCityPress ():Void
	{
		var myColor = new Color(this.cp.arrow_down_city_drawing);
		myColor.setRGB(0x777777);
	}
	
	public function arrowDownCityRelease ():Void
	{
		var currSt:String = radarLocationArray[radarLocationPosition].st;
		
		radarLocationPosition++;
		while (   (currSt != radarLocationArray[radarLocationPosition].st)
		       && (radarLocationPosition < radarLocationArray.length))
		{
			radarLocationPosition++;
		}

		if (radarLocationPosition >= radarLocationArray.length)
		{
			radarLocationPosition = 0;
			while (   (currSt != radarLocationArray[radarLocationPosition].st)
				   && (radarLocationPosition < radarLocationArray.length))
			{
				radarLocationPosition++;
			}
		}
			
		cp.radar_city_txt.text = radarLocationArray[radarLocationPosition].city;
		this.radar_id = String(radarLocationArray[radarLocationPosition].id).toUpperCase();

		var myColor = new Color(this.cp.arrow_down_city_drawing);
		myColor.setRGB(0xFFFFFF);
	}
	
	public function createRadarLocationArray():Array
	{
		var locationArray:Array = new Array();
		
		locationArray[0] = { id:"abc", st:"AK", city:"Bethel" };
		locationArray[1] = { id:"acg", st:"AK", city:"Biorka Is." };
		locationArray[2] = { id:"apd", st:"AK", city:"Fairbanks" };
		locationArray[3] = { id:"ahg", st:"AK", city:"Kenai" };
		locationArray[4] = { id:"akc", st:"AK", city:"King Salmon" };
		locationArray[5] = { id:"aih", st:"AK", city:"Middleton Is." };
		locationArray[6] = { id:"aec", st:"AK", city:"Nome" };
		locationArray[7] = { id:"apd", st:"AK", city:"Pedro Dome" };
		locationArray[8] = { id:"acg", st:"AK", city:"Sitka" };
		locationArray[9] = { id:"bmx", st:"AL", city:"Birmingham" };
		locationArray[10] = { id:"mxx", st:"AL", city:"E. Alabama" };
		locationArray[11] = { id:"eox", st:"AL", city:"Fort Rucker" };
		locationArray[12] = { id:"mob", st:"AL", city:"Mobile" };
		locationArray[13] = { id:"htx", st:"AL", city:"Nrn. Alabama" };
		locationArray[14] = { id:"lzk", st:"AR", city:"Little Rock" };
		locationArray[15] = { id:"srx", st:"AR", city:"W. Ark./Ft. Smith" };
		locationArray[16] = { id:"fsx", st:"AZ", city:"Flagstaff" };
		locationArray[17] = { id:"iwa", st:"AZ", city:"Phoenix" };
		locationArray[18] = { id:"emx", st:"AZ", city:"Tucson" };
		locationArray[19] = { id:"yux", st:"AZ", city:"Yuma" };
		locationArray[20] = { id:"bbx", st:"CA", city:"Beale AFB" };
		locationArray[21] = { id:"eyx", st:"CA", city:"Edwards AFB" };
		locationArray[22] = { id:"bhx", st:"CA", city:"Eureka" };
		locationArray[23] = { id:"hnx", st:"CA", city:"Hanford" };
		locationArray[24] = { id:"vtx", st:"CA", city:"Los Angeles" };
		locationArray[25] = { id:"dax", st:"CA", city:"Sacramento" };
		locationArray[26] = { id:"nkx", st:"CA", city:"San Diego" };
		locationArray[27] = { id:"mux", st:"CA", city:"San Francisco" };
		locationArray[28] = { id:"hnx", st:"CA", city:"San Joaquin Vly." };
		locationArray[29] = { id:"sox", st:"CA", city:"Santa Ana Mtns" };
		locationArray[30] = { id:"vbx", st:"CA", city:"Vandenberg AFB" };
		locationArray[31] = { id:"ftg", st:"CO", city:"Denver/Boulder" };
		locationArray[32] = { id:"gjx", st:"CO", city:"Grand Junction" };
		locationArray[33] = { id:"pux", st:"CO", city:"Pueblo" };
		locationArray[34] = { id:"lwx", st:"DC", city:"Washington DC" };
		locationArray[35] = { id:"dox", st:"DE", city:"Dover AFB" };
		locationArray[36] = { id:"evx", st:"FL", city:"Eglin AFB" };
		locationArray[37] = { id:"jax", st:"FL", city:"Jacksonville" };
		locationArray[38] = { id:"byx", st:"FL", city:"Key West" };
		locationArray[39] = { id:"jax", st:"FL", city:"Melbourne" };
		locationArray[40] = { id:"amx", st:"FL", city:"Miami" };
		locationArray[41] = { id:"evx", st:"FL", city:"NW Florida" };
		locationArray[42] = { id:"tlh", st:"FL", city:"Tallahassee" };
		locationArray[43] = { id:"tbw", st:"FL", city:"Tampa Bay Area" };
		locationArray[44] = { id:"ffc", st:"GA", city:"Atlanta" };
		locationArray[45] = { id:"vax", st:"GA", city:"Moody AFB" };
		locationArray[46] = { id:"jgx", st:"GA", city:"Robins AFB" };
		locationArray[47] = { id:"gua", st:"GU", city:"Andersen AFB" };
		locationArray[48] = { id:"hki", st:"HI", city:"Kauai" };
		locationArray[49] = { id:"hkm", st:"HI", city:"Kohala" };
		locationArray[50] = { id:"hmo", st:"HI", city:"Molokai" };
		locationArray[51] = { id:"hwa", st:"HI", city:"South Shore" };
		locationArray[52] = { id:"dmx", st:"IA", city:"Des Moines" };
		locationArray[53] = { id:"dvn", st:"IA", city:"Quad Cities" };
		locationArray[54] = { id:"cbx", st:"ID", city:"Boise" };
		locationArray[55] = { id:"sfx", st:"ID", city:"Pocatello" };
		locationArray[56] = { id:"ilx", st:"IL", city:"Central IL" };
		locationArray[57] = { id:"lot", st:"IL", city:"Chicago" };
		locationArray[58] = { id:"vwx", st:"IN", city:"Evansville" };
		locationArray[59] = { id:"ind", st:"IN", city:"Indianapolis" };
		locationArray[60] = { id:"iwx", st:"IN", city:"Nrn. Indiana" };
		locationArray[61] = { id:"ddc", st:"KS", city:"Dodge City" };
		locationArray[62] = { id:"gld", st:"KS", city:"Goodland" };
		locationArray[63] = { id:"twx", st:"KS", city:"Topeka" };
		locationArray[64] = { id:"ict", st:"KS", city:"Wichita" };
		locationArray[65] = { id:"hpx", st:"KY", city:"Fort Cambell" };
		locationArray[66] = { id:"jkl", st:"KY", city:"Jackson" };
		locationArray[67] = { id:"lvx", st:"KY", city:"Louisville" };
		locationArray[68] = { id:"pah", st:"KY", city:"Paducah" };
		locationArray[69] = { id:"poe", st:"LA", city:"Fort Polk" };
		locationArray[70] = { id:"lch", st:"LA", city:"Lake Charles" };
		locationArray[71] = { id:"lix", st:"LA", city:"New Orleans" };
		locationArray[72] = { id:"shv", st:"LA", city:"Shreveport" };
		locationArray[73] = { id:"box", st:"MA", city:"Boston" };
		locationArray[74] = { id:"lwx", st:"MD", city:"Baltimore" };
		locationArray[75] = { id:"cbw", st:"ME", city:"Caribou" };
		locationArray[76] = { id:"gyx", st:"ME", city:"Portland" };
		locationArray[77] = { id:"dtx", st:"MI", city:"Detroit" };		
		locationArray[78] = { id:"apx", st:"MI", city:"Gaylord" };
		locationArray[79] = { id:"grr", st:"MI", city:"Grand Rapids" };
		locationArray[80] = { id:"mqt", st:"MI", city:"Marquette" };
		locationArray[81] = { id:"dlh", st:"MN", city:"Duluth" };
		locationArray[82] = { id:"mpx", st:"MN", city:"Minneapolis" };
		locationArray[83] = { id:"eax", st:"MO", city:"Kansas City" };
		locationArray[84] = { id:"sgf", st:"MO", city:"Springfield" };
		locationArray[85] = { id:"lsx", st:"MO", city:"St. Louis" };
		locationArray[86] = { id:"gwx", st:"MS", city:"Columbus AFB" };
		locationArray[87] = { id:"dgx", st:"MS", city:"Jackson/Brandon" };
		locationArray[88] = { id:"blx", st:"MT", city:"Billings" };
		locationArray[89] = { id:"ggw", st:"MT", city:"Glasgow" };
		locationArray[90] = { id:"tfx", st:"MT", city:"Great Falls" };
		locationArray[91] = { id:"msx", st:"MT", city:"Missoula" };
		locationArray[92] = { id:"rax", st:"NC", city:"Durham" };
		locationArray[93] = { id:"mhx", st:"NC", city:"Morehead City" };
		locationArray[94] = { id:"rax", st:"NC", city:"Raleigh" };
		locationArray[95] = { id:"ltx", st:"NC", city:"Wilmington" };
		locationArray[96] = { id:"bis", st:"ND", city:"Bismarck" };
		locationArray[97] = { id:"mvx", st:"ND", city:"Grand Forks" };
		locationArray[98] = { id:"mbx", st:"ND", city:"Minot AFB" };
		locationArray[99] = { id:"uex", st:"NE", city:"Hastings" };
		locationArray[100] = { id:"lnx", st:"NE", city:"North Platte" };
		locationArray[101] = { id:"oax", st:"NE", city:"Omaha" };
		locationArray[102] = { id:"dix", st:"NJ", city:"Mt. Holly" };
		locationArray[103] = { id:"abx", st:"NM", city:"Albuquerque" };
		locationArray[104] = { id:"fdx", st:"NM", city:"Cannon AFB" };
		locationArray[105] = { id:"hdx", st:"NM", city:"Holloman AFB" };
		locationArray[106] = { id:"lrx", st:"NV", city:"Elko" };
		locationArray[107] = { id:"esx", st:"NV", city:"Las Vegas" };
		locationArray[108] = { id:"rgx", st:"NV", city:"Reno" };
		locationArray[109] = { id:"hdx", st:"NY", city:"Albany" };
		locationArray[110] = { id:"bgm", st:"NY", city:"Binghamton" };
		locationArray[111] = { id:"buf", st:"NY", city:"Buffalo" };
		locationArray[112] = { id:"tyx", st:"NY", city:"Montague" };
		locationArray[113] = { id:"okx", st:"NY", city:"New York City" };
		locationArray[114] = { id:"iln", st:"OH", city:"Cincinnati" };
		locationArray[115] = { id:"cle", st:"OH", city:"Cleveland" };
		locationArray[116] = { id:"iln", st:"OH", city:"Dayton" };
		locationArray[117] = { id:"iln", st:"OH", city:"Wilmington" };
		locationArray[118] = { id:"fdr", st:"OK", city:"Frederick" };
		locationArray[119] = { id:"tlx", st:"OK", city:"Oklahoma City" };
		locationArray[120] = { id:"inx", st:"OK", city:"Tulsa" };
		locationArray[121] = { id:"vnx", st:"OK", city:"Vance AFB" };
		locationArray[122] = { id:"max", st:"OR", city:"Medford" };
		locationArray[123] = { id:"pdt", st:"OR", city:"Pendleton" };
		locationArray[124] = { id:"rtx", st:"OR", city:"Portland" };
		locationArray[125] = { id:"dix", st:"PA", city:"Philadelphia" };
		locationArray[126] = { id:"pbz", st:"PA", city:"Pittsburgh" };
		locationArray[127] = { id:"ccx", st:"PA", city:"State College" };
		locationArray[128] = { id:"jua", st:"PR", city:"Puerto Rico/V.I." };
		locationArray[129] = { id:"clx", st:"SC", city:"Charleston" };
		locationArray[130] = { id:"cae", st:"SC", city:"Columbia" };
		locationArray[131] = { id:"gsp", st:"SC", city:"Greenville" };
		locationArray[132] = { id:"gsp", st:"SC", city:"Spartanburg" };
		locationArray[133] = { id:"gsp", st:"SC", city:"Greer" };
		locationArray[134] = { id:"abr", st:"SD", city:"Aberdeen" };
		locationArray[135] = { id:"udx", st:"SD", city:"Rapid City" };
		locationArray[136] = { id:"fsd", st:"SD", city:"Sioux falls" };
		locationArray[137] = { id:"mrx", st:"TN", city:"Knoxville" };
		locationArray[138] = { id:"nqa", st:"TN", city:"Memphis" };
		locationArray[139] = { id:"mrx", st:"TN", city:"Morristown" };
		locationArray[140] = { id:"ohx", st:"TN", city:"Nashville" };
		locationArray[141] = { id:"mrx", st:"TN", city:"Tri Cities" };
		locationArray[142] = { id:"ama", st:"TX", city:"Amarillo" };
		locationArray[143] = { id:"ewx", st:"TX", city:"Austin" };
		locationArray[144] = { id:"bro", st:"TX", city:"Brownsville" };
		locationArray[145] = { id:"grk", st:"TX", city:"Central Texas" };
		locationArray[146] = { id:"crp", st:"TX", city:"Corpus Christi" };
		locationArray[147] = { id:"fws", st:"TX", city:"Dallas" };
		locationArray[148] = { id:"dyx", st:"TX", city:"Dyess AFB" };
		locationArray[149] = { id:"epz", st:"TX", city:"El Paso" };
		locationArray[150] = { id:"fws", st:"TX", city:"Fort Worth" };
		locationArray[151] = { id:"hgx", st:"TX", city:"Galveston" };
		locationArray[152] = { id:"hgx", st:"TX", city:"Houston" };
		locationArray[153] = { id:"dfx", st:"TX", city:"Laughlin AFB" };
		locationArray[154] = { id:"lbb", st:"TX", city:"Lubbock" };
		locationArray[155] = { id:"maf", st:"TX", city:"Midland/Odessa" };
		locationArray[156] = { id:"sjt", st:"TX", city:"San Angelo" };
		locationArray[157] = { id:"ewx", st:"TX", city:"San Antonio" };
		locationArray[158] = { id:"icx", st:"UT", city:"Cedar City" };
		locationArray[159] = { id:"mtx", st:"UT", city:"Salt Lake City" };
		locationArray[160] = { id:"fcx", st:"VA", city:"Blacksburg" };
		locationArray[161] = { id:"akq", st:"VA", city:"Norfolk" };
		locationArray[162] = { id:"akq", st:"VA", city:"Richmond" };
		locationArray[163] = { id:"fcx", st:"VA", city:"Roanoke" };
		locationArray[164] = { id:"lwx", st:"VA", city:"Sterling" };
		locationArray[165] = { id:"akq", st:"VA", city:"Wakefield" };
		locationArray[166] = { id:"cxx", st:"VT", city:"Burlington" };
		locationArray[167] = { id:"atx", st:"WA", city:"Seattle" };
		locationArray[168] = { id:"otx", st:"WA", city:"Spokane" };
		locationArray[169] = { id:"atx", st:"WA", city:"Tacoma" };
		locationArray[170] = { id:"grb", st:"WI", city:"Green Bay" };
		locationArray[171] = { id:"arx", st:"WI", city:"La Crosse" };
		locationArray[172] = { id:"mkx", st:"WI", city:"Milwaukee" };
		locationArray[173] = { id:"rlx", st:"WV", city:"Charleston" };
		locationArray[174] = { id:"cys", st:"WY", city:"Cheyenne" };
		locationArray[175] = { id:"riw", st:"WY", city:"Riverton" };
		
		return locationArray;

	}
	
	public function showTextMessage (myText:String, myTextSize:Number):Void 
	{
		// Delete any other previous messages if there
		deleteTextMessage();
		
		_text_holder = cp.createEmptyMovieClip("text_holder", cp.getNextHighestDepth());
		_text_holder.createTextField("t", _text_holder.getNextHighestDepth(), 220, 127, 100, 30);

		var tf:TextFormat = new TextFormat();
		tf.size = myTextSize*_x_scale_factor;
		tf.align = "right";
		tf.color = 0xFFFFFF;
		
		tf.bold = true;
		tf.font = "_sans"; //also _serif and _typewriter available for chumby

		_text_holder.t.setNewTextFormat(tf);
		_text_holder.t.text = myText;											
		_text_holder.t.wordWrap = false;
		delete tf;
	}
	
	public function deleteTextMessage ():Void
	{
		if (_text_holder != null)
		{
			_text_holder.t.removeTextField();
			_app_root.removeMovieClip(_text_holder);
			_text_holder = null;
		}
	}

}